﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Traders.Controllers;
using Traders.Models;

namespace Traders.Views
{
    public partial class OpenTradesView : UserControl, TradersView
    {
        public OpenTradesView()
        {
            InitializeComponent();
        }

        public DataTable DataTable
        {
            get { return (DataTable)this.openTradesDataGridView.DataSource; }
            set { this.openTradesDataGridView.DataSource = value; }
        }

        public event EventHandler<TradersEventArgs> EventHandler;

        public void FireEvent(TradersEventArgs e)
        {
            if (EventHandler != null)
                EventHandler(this, e);
        }

        public void HandleEvent(object sender, TradersEventArgs e)
        {
            switch (e.Action)
            {
                case "CloseTradeError":
                    if (e.Tag is int) MessageBox.Show("Błąd przy zamykaniu zlecenia o tickecie: " + (int)e.Tag);
                    break;
            }
        }

        private void closeTrade_Click(object sender, EventArgs e)
        {
            TradersEventArgs args = new TradersEventArgs();
            args.Action = "CloseTradeClicked";
            args.Tag = openTradesDataGridView.SelectedRows;
            FireEvent(args);
            // TODO: Dodać wyłączanie guzika do zamykania zleceń i włączać go po zakończeniu procedury zamykania.
        }

    }
}
